/*
 * @Author: zjj
 * @Date: 2020-02-22 10:33:23
 * @LastEditors: zjj
 * @LastEditTime: 2020-02-22 10:35:14
 */
import CryptoJS from "crypto-js";
var myMixin = {
    methods: {
        MD5(password) {
            return CryptoJS.MD5(password).toString()
        },
        //加密aes
        encrypt(data, _key, _iv) {
            // let text = JSON.stringify(data);
            let text = CryptoJS.enc.Base64.stringify(
                CryptoJS.enc.Utf8.parse(data)
            ).toString();
            let key = CryptoJS.enc.Utf8.parse(_key); //为了避免补位，直接用16位的秘钥
            let iv = CryptoJS.enc.Utf8.parse(_iv); //16位初始向量
            let encrypted = CryptoJS.AES.encrypt(text, key, {
                iv: iv,
                mode: CryptoJS.mode.CBC,
                padding: CryptoJS.pad.ZeroPadding
            }).toString();
            return CryptoJS.enc.Base64.stringify(
                CryptoJS.enc.Utf8.parse(encrypted)
            ).toString();
        }
    },
}

export default myMixin